<template>
  <div class="app-container" v-infinite-scroll="load" :infinite-scroll-immediate="false">

    <div class="content">
      <el-card class="box-card mt" v-for="url in files" :key="url" :body-style="{ padding: '0px' }">
        <photo-home-photo :data="url" class="photoImage" />
      </el-card>
    </div>
  </div>
</template>

<script>
import { queryData, preview } from "@/api/file/file";
// import pagination from "@/components/Pagination"; // Secondary package based on el-pagination


export default {
  name: "photo",
  data() {
    return {
      files: [],
      query: {
        currentPage: 1,
        pageSize: 4
      },
    };
  },
  computed: {},
  created() {
    this.getList();
  },
  methods: {
    async load() {
      await this.getList();
    },
    async getList() {
      let res  = await queryData(this.query)
      // this.listLoading = true;
     // queryData(this.query).then(async (res) => {
        //this.list = res;
        //debugger
        let result = res.result.data;
        for (let file of result) {
          const img = await preview(file.id)
          const imgUrl = (window.URL || window.webkitURL).createObjectURL(img)
          file.url = imgUrl
        }

        this.files.push(result)
        //this.total = res.result.total;
        this.query.currentPage = res.result.nextPage;
      //});


      //this.listLoading = false;

    },
    async getPreview(item) {
      //if (item.url === item.id) {
      const img = await preview(item.id)
      const imgUrl = (window.URL || window.webkitURL).createObjectURL(img)

      item.url = imgUrl
      //.set(item, 'url', imgUrl);

      //this.$set(item, 'url', imgUrl)
      //this.$set(item, 'originalUrl', imgUrl)
      //}
    },
  },
  mounted: function () { },
  watch: {
    query: {
      handler(val, oldVal) {
        console.log(this.query)
        //this.getList();
      },
      deep: true
    },
  }
};
</script>

<style lang="scss">
.app-container {
  height: calc(100vh - 180px);
  overflow-y: auto;

}

.content {

  display: flex;
  flex-wrap: wrap;

  .ep-card {
    width: 200px;
    height: 300px;
    margin: 10px;
    flex-grow: 1;

    .ep-card__body {
      width: 100%;
      height: 100%;
    }

    .photoImage {
      width: 100%;
      height: 100%;
      overflow: hidden;
    }

    .ep-image {
      width: 100%;
      height: 100%;
    }


  }
}
</style>


